package com.ruoyi.material.controller;

import java.text.DecimalFormat;
import java.util.*;

import com.ruoyi.material.domain.BaseMaterial;
import com.ruoyi.material.service.IBaseMaterialService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.BaseTagFile;
import com.ruoyi.material.service.IBaseTagFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标记文件信息Controller
 * 
 * @author ruoyi
 * @date 2021-07-20
 */
@RestController
@RequestMapping("/material/tag_file")
public class BaseTagFileController extends BaseController
{
    @Autowired
    private IBaseTagFileService baseTagFileService;
    @Autowired
    private IBaseMaterialService baseMaterialService;

    /**
     * 查询标记文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('material:tag_file:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseTagFile baseTagFile)
    {
        startPage();
        BaseMaterial baseMaterial = baseMaterialService.selectBMByFileCode(baseTagFile.getFileCode().intValue());
        baseTagFile.setFileCode(baseMaterial.getTabCode());
        List<BaseTagFile> list = baseTagFileService.selectBaseTagFileList(baseTagFile);
        Iterator<BaseTagFile> it = list.iterator();
        while(it.hasNext()){//目前控制标记值为4个的时候才会画框，否则不画出来
            BaseTagFile btf = it.next();
            String[] oldInfoStr=btf.getTagInfo().split(" ");
            if(oldInfoStr.length!=4){
                it.remove();
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出标记文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('material:tag_file:export')")
    @Log(title = "标记文件信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseTagFile baseTagFile)
    {
        List<BaseTagFile> list = baseTagFileService.selectBaseTagFileList(baseTagFile);
        ExcelUtil<BaseTagFile> util = new ExcelUtil<BaseTagFile>(BaseTagFile.class);
        return util.exportExcel(list, "标记文件信息数据");
    }

    /**
     * 获取标记文件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:tag_file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseTagFileService.selectBaseTagFileById(id));
    }

    /**
     * 新增标记文件信息
     */
    @PreAuthorize("@ss.hasPermi('material:tag_file:add')")
    @Log(title = "标记文件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseTagFile baseTagFile)
    {
        return toAjax(baseTagFileService.insertBaseTagFile(baseTagFile));
    }

    /**
     * 修改标记文件信息
     */
    @PreAuthorize("@ss.hasPermi('material:tag_file:edit')")
    @Log(title = "标记文件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseTagFile baseTagFile)
    {
        return toAjax(baseTagFileService.updateBaseTagFile(baseTagFile));
    }

    /**
     * 删除标记文件信息
     */
    @PreAuthorize("@ss.hasPermi('material:tag_file:remove')")
    @Log(title = "标记文件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseTagFileService.deleteBaseTagFileByIds(ids));
    }
}
